#include "mem_pool_manager.h"
#include <cstring>
#include <iostream>

int32_t main() {
  int32_t main_res{0};

  try {
    const std::shared_ptr<MemTest::MemPool> test_pool =
        std::make_shared<MemTest::MemPool>("test_pool", 65536, 600, 32, true);

    int8_t *const buffer1 = test_pool->mem_alloc();
    if (buffer1 != nullptr) {
      // std::cout << "Memory allocated by: " << mem_delegate->get_allocator_name(buffer1) << std::endl;

      const char *const str1 = "Hello, World!";
      strncpy(reinterpret_cast<char *>(buffer1), str1, 100);

      std::cout << "Content of buffer1: " << reinterpret_cast<char *>(buffer1) << std::endl;
    } else {
      std::cout << "Memory allocation failed." << std::endl;
    }

    int8_t *const buffer2 = test_pool->mem_alloc();
    if (buffer2 != nullptr) {
      // std::cout << "Memory allocated by: " << mem_delegate->get_allocator_name(buffer2) << std::endl;

      const char *const str2 = "This is a test.";
      strncpy(reinterpret_cast<char *>(buffer2), str2, 50);

      std::cout << "Content of buffer2: " << reinterpret_cast<char *>(buffer2) << std::endl;
    } else {
      std::cout << "Memory allocation failed." << std::endl;
    }

    test_pool->mem_free(buffer1);
    test_pool->mem_free(buffer2);
  } catch (...) {
    std::cerr << "Exception occurred" << std::endl;
    main_res = 1;
  }

  return main_res;
}
